<?php
$name = isset($name)?$name:"menu[parentID]";	//select的name值
$parentID = isset($parentID)?$parentID:0;		
$menuID = isset($menuID)?$menuID:0;
$show = isset($show)?$show:0;	//是否显示"顶级菜单"
$topMenu = service_menu::getTopMenu();
$menus = service_menu::getAll();
function getSubMenu($menus,$parentID){
	$items = array();
	foreach($menus as $menu){
		if($menu['parentID'] == $parentID){
			$items[] = $menu;
		}
	}
	return $items;
}
function menuOption($menus,$menu,$parentID,$menuID,$show=0){
	if(!($menuID == $menu['id'])){
		$str = "<option value='".$menu['id']."' ";
		if($menu['id']==$parentID){
			$str .= " selected='selected' ";
		}
		$num = $show?substr_count($menu['path'],','):substr_count($menu['path'],',')-1;
		$str .= " >".str_repeat('&ndash;',$num).$menu['title']."</option>";
		echo $str;
		$children = getSubMenu($menus,$menu['id']);
		if(!empty($children)){
			foreach($children as $child){
				menuOption($menus,$child,$parentID,$menuID,$show);
			}
		}
	}
}
?>
<select name="<?php echo $name;?>" >
	<?php if($show):?>
	<option value="0">顶级菜单</option>
	<?php endif;?>
	<?php foreach($topMenu as $menu):?>
		<?php menuOption($menus,$menu,$parentID,$menuID,$show);?>
	<?php endforeach;?>
</select>

